/***************************************************************
 * Name:      GanitSheetsApp.cpp
 * Purpose:   Code for Application Class
 * Author:    Milind Gupta (milind.gupta@gmail.com)
 * Website:   https://code.google.com/p/ganitsheets/
 * Created:   2011-02-12
 * Copyright: Milind Gupta ()
 * License:
 **************************************************************/

// Include Files
#include "GanitSheetsApp.h"

IMPLEMENT_APP(GanitSheetsApp);

bool GanitSheetsApp::OnInit()
{
    //(*AppInitialize
    bool wxsOK = true;
    wxInitAllImageHandlers();
    // Load Lua here
    luaVM = lua_open();
    this->setTZ(wxDateTime::Local);
    if(NULL==luaVM)
        return false;   // Cannot run the software without a Lua Virtual machine
    if ( wxsOK )
    {
        // Load the Lua Libraries
        luaL_openlibs(luaVM);
        wxWindowID frameID = wxNewId();
    	Frame = new GanitSheetsFrame(NULL, this, frameID);
    	Frame->Show();
    	SetTopWindow(Frame);
        if(runLuaFile(luaInitFile).returnCode==retPacket::ERR)
            Frame->addLogMsg("Error executing Lua Initialization File: " + luaInitFile);
        else
            Frame->addLogMsg("Initialization Finished on " + \
                std::string(wxDateTime::Now().Format(wxDefaultDateTimeFormat, currTZ).mb_str()));
    }
    //*)
    return wxsOK;
}

void GanitSheetsApp::setTZ(wxDateTime::TZ newTZ)
{
    currTZ = newTZ;
}
